import 'dart:ui';

import 'package:whale/helper/utils/util.dart';

import 'problem_list.dart';

class TPTextModel {
  String? id;
  String? documentTitle;
  String? documentNum;
  String? documentTag;
  String? documentText;
  String? documentUrl;
  String? industryType;
  String? companyType;
  String? companyName;
  String? reportType;
  String? problemType;
  dynamic projectPrice;
  String? hasProblem;
  int? documentScore;
  String? riskLevel;
  String? publishTime;
  String? province;
  String? city;
  String? area;
  int? linkType;
  String? linkId;
  String? genre;
  String? indexNumber;
  String? concats;
  String? concatsPhone;
  String? purchaseAgency;
  String? projectName;
  String? isValid;
  String? tenantId;
  String? createBy;
  String? createTime;
  String? updateBy;
  String? updateTime;
  List<ProblemList>? problemList;
  List<dynamic>? appendixList;

  /// 0 textColor  1 backgroundColor
  List<Color> get riskColors {
    if (riskLevel == '高风险') {
      return const [Color(0xffE55F5F)];
    }

    if (riskLevel == '低风险') {
      return const [Color(0xff228FFA)];
    }

    if (riskLevel == '中风险') {
      return const [Color(0xffEB932F)];
    }

    return const [Color(0xff57BB72)];
  }

  TPTextModel({
    this.id,
    this.documentTitle,
    this.documentNum,
    this.documentTag,
    this.documentText,
    this.documentUrl,
    this.industryType,
    this.companyType,
    this.companyName,
    this.reportType,
    this.problemType,
    this.projectPrice,
    this.hasProblem,
    this.documentScore,
    this.riskLevel,
    this.publishTime,
    this.province,
    this.city,
    this.area,
    this.linkType,
    this.linkId,
    this.genre,
    this.indexNumber,
    this.concats,
    this.concatsPhone,
    this.purchaseAgency,
    this.projectName,
    this.isValid,
    this.tenantId,
    this.createBy,
    this.createTime,
    this.updateBy,
    this.updateTime,
    this.problemList,
    this.appendixList,
  });

  factory TPTextModel.fromJson(Map<String, dynamic> json) {
    String riskLevel = json['riskLevel'].toString();
    if (riskLevel.length > 3) {
      riskLevel = riskLevel.substring(1, 4);
    }
    return TPTextModel(
      id: json['id'] as String?,
      documentTitle: json['documentTitle'] as String?,
      documentNum: json['documentNum'] as String?,
      documentTag: json['documentTag'] as String?,
      documentText: json['documentText'] as String?,
      documentUrl: json['documentUrl'] as String?,
      industryType: json['industryType'] as String?,
      companyType: json['companyType'] as String?,
      companyName: json['companyName'] as String?,
      reportType: json['reportType'] as String?,
      problemType: json['problemType'] as String?,
      projectPrice: json['projectPrice'] as dynamic,
      hasProblem: json['hasProblem'] as String?,
      documentScore: numVal(json['documentScore']).toInt(),
      riskLevel: riskLevel,
      publishTime: json['publishTime'] as String?,
      province: json['province'] as String?,
      city: json['city'] as String?,
      area: json['area'] as String?,
      linkType: json['linkType'] as int?,
      linkId: json['linkId'] as String?,
      genre: json['genre'] as String?,
      indexNumber: json['indexNumber'] as String?,
      concats: json['concats'] as String?,
      concatsPhone: json['concatsPhone'] as String?,
      purchaseAgency: json['purchaseAgency'] as String?,
      projectName: json['projectName'] as String?,
      isValid: json['isValid'] as String?,
      tenantId: json['tenantId'] as String?,
      createBy: json['createBy'] as String?,
      createTime: json['createTime'] as String?,
      updateBy: json['updateBy'] as String?,
      updateTime: json['updateTime'] as String?,
      problemList: (json['problemList'] as List<dynamic>?)
          ?.map((e) => ProblemList.fromJson(e as Map<String, dynamic>))
          .toList(),
      appendixList: json['appendixList'] as List<dynamic>?,
    );
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        'documentTitle': documentTitle,
        'documentNum': documentNum,
        'documentTag': documentTag,
        'documentText': documentText,
        'documentUrl': documentUrl,
        'industryType': industryType,
        'companyType': companyType,
        'companyName': companyName,
        'reportType': reportType,
        'problemType': problemType,
        'projectPrice': projectPrice,
        'hasProblem': hasProblem,
        'documentScore': documentScore,
        'riskLevel': riskLevel,
        'publishTime': publishTime,
        'province': province,
        'city': city,
        'area': area,
        'linkType': linkType,
        'linkId': linkId,
        'genre': genre,
        'indexNumber': indexNumber,
        'concats': concats,
        'concatsPhone': concatsPhone,
        'purchaseAgency': purchaseAgency,
        'projectName': projectName,
        'isValid': isValid,
        'tenantId': tenantId,
        'createBy': createBy,
        'createTime': createTime,
        'updateBy': updateBy,
        'updateTime': updateTime,
        'problemList': problemList?.map((e) => e.toJson()).toList(),
        'appendixList': appendixList,
      };
}
